<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.mselect.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.multiselect.js"></script>
<script type="text/javascript">
get_check = function(){
	var ids = '';
	$("#list").find("input[type='checkbox']").each(function(){
		if ($(this).is(":checked"))
		{
			if (ids)
			{
				ids += ',';
			}
			ids += $(this).val();
		}
	});
	return ids;
}
$(function(){
	$(".datepicker").datepicker({dateFormat: 'yy-mm-dd', changeMonth: true});
	$("#shop_ids").multiselect({height: 260, minWidth: 160});
	$(".addnotes_btn").click(function(){
		$("#dialog_notes").find(":input[name='id']").val($(this).next().val());
		$("#dialog_notes").dialog("open");
	});
	$("#dialog_notes").dialog({autoOpen: false, modal: true});
	$("#check_all").click(function(){
		if ($(this).is(":checked"))
		{
			$("#list input[type='checkbox']:enabled").attr("checked", true);
		}
		else
		{
			$("#list input[type='checkbox']").attr("checked", false);
		}
	});
	var old_info = $(this).val();
	$(".edit").keypress(function(event){
		if (event.which == 13)
		{
			$(this).blur();
		}
	});
	$(".edit").focus(function(){
		$(this).removeClass("blur");
		old_info = $(this).val();
	}).blur(function(){
		var current_tag = $(this);
		var id = $(this).next().val();
		var new_info = $(this).val();
		if (new_info != old_info)
		{
			$.ajax({
				url: "<?=url('Services::EbayFeedback/ProductNumberEditSave')?>&product_number=" + new_info + "&id=" + id,
				type: "GET",
				dataType: "json",
				success:
					function(data)
					{
						if (data['ack'] == 'success')
						{
							current_tag.val(data['product_number']);
							current_tag.parent().attr('title', data['product_name']);
						}
						else
						{
							current_tag.val(old_info);
						}
					}
			});
		}
		current_tag.addClass("blur");
	});
	$(".export_check_btn").click(function(){
		var ids = get_check();
		if (ids.length == 0)
		{
			alert('请选择要导出的评价信息');
			return false;
		}
		window.location.href="<?=url('Services::EbayFeedback/ExportFeedbackInfo')?>&ids=" + ids;
	});
	$(".export_search_btn").click(function(){
		if (confirm('确定导出所有符合条件的评价信息？'))
		{
			window.location.href='<?=url('Services::EbayFeedback/ExportFeedbackInfo')?>&url_json=<?=$url_json?>';
		}
	});
});
</script>
<style>
.blur {cursor: pointer; border: none;}
</style>
<fieldset><legend>查询条件</legend>
<form method="get">
<?include (Q::ini('custom_system/elements_dir') . 'searchform_element.php');?>
<table class="form_table" width="100%">
<tr>
	<th width="50">评价时间</th>
	<td>
		<input type="text" class="datepicker" name="begin_create_time" value="<?=isset($_GET['begin_create_time']) ? $_GET['begin_create_time'] : ''?>" /> to
		<input type="text" class="datepicker" name="end_create_time" value="<?=isset($_GET['end_create_time']) ? $_GET['end_create_time'] : ''?>" />
	</td>
</tr>
<tr>
	<th width="50">发货时间</th>
	<td>
		<input type="text" class="datepicker" name="begin_shipped_time" value="<?=isset($_GET['begin_shipped_time']) ? $_GET['begin_shipped_time'] : ''?>" /> to
		<input type="text" class="datepicker" name="end_shipped_time" value="<?=isset($_GET['end_shipped_time']) ? $_GET['end_shipped_time'] : ''?>" />
	</td>
</tr>
<tr>
	<th>店铺</th>
	<td>
		<select name="shop_ids[]" multiple="multiple" id="shop_ids">
			<optgroup label="ebay">
				<?foreach ($shop as $s):?>
				<option value="<?=$s['id']?>" <?if (isset($_GET['shop_ids']) && in_array($s['id'], $_GET['shop_ids'])):?>selected="selected"<?endif;?>><?=$s['name']?></option>
				<?endforeach;?>
			</optgroup>
		</select>
	</td>
</tr>
<tr>
	<th>国家</th>
	<td>
		<select name="country">
			<option value="">请选择..</option>
			<?foreach($country as $c):?>
			<option value="<?=$c['en_name']?>" <?if (isset($_GET['country']) && $c['en_name'] == $_GET['country']):?>selected="selected"<?endif;?>><?=$c['en_name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>顾客名称</th>
	<td><input type="text" name="user" value="<?=isset($_GET['user']) ? $_GET['user'] : ''?>" /></td>
</tr>
<tr>
	<th>ItemID</th>
	<td><input type="text" name="shop_item_id" value="<?=isset($_GET['shop_item_id']) ? $_GET['shop_item_id'] : ''?>" /></td>
</tr>
<tr>
	<th>交易号</th>
	<td><input type="text" name="transaction_id" value="<?=isset($_GET['transaction_id']) ? $_GET['transaction_id'] : ''?>" /></td>
</tr>
<tr>
	<th>邮寄方式</th>
	<td colspan="3">
		<table>
		<?foreach ($shipping_method as $sm):?>
		<tr>
			<th><strong><?=$sm['name']?>：</strong></th>
			<td style="padding: 1px;">
				<?foreach ($sm['children'] as $v):?>
				<label style="float: left;"><input type="checkbox" name="shipping_method[<?=$v['id']?>]" value="<?=$v['id']?>" <?if (isset($_GET['shipping_method']) && array_key_exists($v['id'], $_GET['shipping_method'])) echo "checked='checked'"?> /> <?=$v['name']?>&nbsp;</label>
				<?endforeach;?>
			</td>
		</tr>
		<?endforeach;?>
		</table>
	</td>
</tr>
<tr>
	<th>类型</th>
	<td>
		<?foreach(Helper_BSS_Normal::getIniAll('services_ebay_feedback_type', array('display' => 1)) as $t):?>
		<label><input type="checkbox" name="type[<?=$t['value']?>]" value="<?=$t['value']?>" <?=isset($_GET['type']) && in_array($t['value'], $_GET['type']) ? 'checked="checked"' : ''?> /> <?=$t['name']?></label> 
		<?endforeach;?>
	</td>
</tr>
<tr>
	<td></td>
	<td><input type="submit" class="button" value="查询" /></td>
</tr>
</table>
</form>
</fieldset>
<table class="list_table" width="100%" id="list">
<tr>
	<th width="30"></th>
	<th>顾客名称</th>
	<th>店铺</th>
	<th>产品编号</th>
	<th width="100">产品名称</th>
	<th>单价</th>
	<th width="150">内容</th>
	<th width="80">发货时间</th>
	<th width="80">评价时间</th>
	<th>间隔(天)</th>
	<th>国家</th>
	<th>邮寄</th>
	<th>备注</th>
	<th>操作</th>
</tr>
<?foreach ($feedback as $f):?>
<tr>
	<td><input type="checkbox" value="<?=$f['id']?>" /></td>
	<td align="left">
		<span class="<?=Helper_BSS_Normal::getIniOne('services_ebay_feedback_type', 'value', $f['type'], 'icon_class')?>" title="<?=Helper_BSS_Normal::getIniOne('services_ebay_feedback_type', 'value', $f['type'], 'name')?>"></span>
		<?=$f['user']?>
	</td>
	<td><?=$f['shop_name']?></td>
	<td>
		<input type="text" value="<?=$f['product_number']?>" class="edit blur" size="7" />
		<input type="hidden" value="<?=$f['id']?>" />
	</td>
	<td><?=$f['product_name']?></td>
	<td><?=$f['currency_symbol']?><?=sprintf('%.2f', $f['item_price'])?></td>
	<td align="left"><?=$f['content']?></td>
	<td><?=$f['shipped_time']?></td>
	<td title="创建时间：<?=$f['create_time'] . "\n"?>
销售时间：<?=$f['sales_time'] . "\n"?>
发货时间：<?=$f['shipped_time']?>
	"><?=$f['create_time']?></td>
	<td><?=$f['shipped_time'] ? ceil(((strtotime($f['create_time']) - strtotime($f['shipped_time'])) / (3600 * 24))) : ''?></td>
	<td><?=$f['country']?></td>
	<td><?=$f['shipping_method_name']?></td>
	<td><?=$f['notes']?></td>
	<td>
		<a href="<?=url('Services::EbayMessage/ContactMember', array('shop_item_id' => $f['shop_item_id'], 'user' => $f['user']))?>">联系顾客</a>
		<a href="javascript: void(0);" class="addnotes_btn">备注</a>
		<input type="hidden" value="<?=$f['id']?>" />
	</td>
</tr>
<?endforeach;?>
</table>
<?=$page;?>
<table class="list_table">
<tr>
	<td><label><input type="checkbox" id="check_all" />全选</label></td>
	<td>导出评价：
		<input type="button" class="button export_check_btn" value="按勾选" />
		<input type="button" class="button export_search_btn" value="按条件" />
	</td>
</tr>
</table>
<div id="dialog_notes" title="填写备注">
<form method="post" action="<?=url('Services::EbayFeedback/AddNotes')?>">
	<input type="hidden" name="id" value="" />
	<input type="hidden" name="<?=Q::ini('unique_token_name')?>" value="<?=Helper_BSS_Normal::genToken()?>" />
	<p><textarea name="notes" rows="3" cols="35"></textarea></p>
	<p><input type="submit" value="附加备注" class="button" /></p>
</form>
</div>
<form id="export_form" action="" method="post">
	<input type="hidden" name="ids" id="export_ids" value="" />
	<input type="hidden" name="url_json" value="<?=$url_json?>" />
</form>
<?php $this->_endblock(); ?>